<?php

/* -----------------------------------------------------------------
 * 	$Id: blog_edit_item_block.php 959 2014-04-10 05:31:01Z sbraeutig $
 * 	Copyright (c) 2011-2021 commerce:SEO by Webdesign Erfurt
 * Copyright by H&S eCom 
 * @author little Pit(S.B.)
 * 	http://www.commerce-seo.de : www.indiv-style.de
 * ------------------------------------------------------------------
 * 	based on:
 * 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
 * 	(c) 2002-2003 osCommerce - www.oscommerce.com
 * 	(c) 2003     nextcommerce - www.nextcommerce.org
 * 	(c) 2005     xt:Commerce - www.xt-commerce.com
 * 	Released under the GNU General Public License
 * --------------------------------------------------------------- */

defined("_VALID_XTC") or die("Direct access to this location isn't allowed.");
for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
	if (USE_WYSIWYG == 'true') {
		if (file_exists('includes/ckfinder/ckfinder.js')) {
			$field_sdesc_wy = "<script src=\"includes/ckfinder/ckfinder.js\"></script>
								<script>
									var newCKEdit = CKEDITOR.replace('mydesc_" . $languages[$i]['id'] . "');
									CKFinder.setupCKEditor(newCKEdit, 'includes/ckfinder/');
								</script>
								";
		} else {
			$field_sdesc_wy = "<script>
								CKEDITOR.replace('mydesc_" . $languages[$i]['id'] . "', {
									toolbar: \"ImageMapper\",
									language: \"" . $_SESSION['language_code'] . "\",
									baseHref: \"" . (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG . "\",
									filebrowserBrowseUrl: \"includes/ckeditor/filemanager/index.html\"
								});
							</script>
			";
		}
	}

    $itemedit2[$i] = array(
        'id' => (int) $_GET['item'],
        'langid' => $languages[$i]['id'],
        'langname' => $languages[$i]['name'],
        'field_mydesc' => xtc_draw_textarea_field('mydesc_' . $languages[$i]['id'], '', '100', '50', '', ''),
        'field_sdesc_wy' => $field_sdesc_wy
    );
}


$selblog[0] = array('id' => '0', 'text' => 'Alle');
$i = 1;
$r = 0;
$myitem_query = xtc_db_query("SELECT * FROM blog_items WHERE language_id = '" . (int) $_SESSION['languages_id'] . "' AND status = '2';");
$caterlaubt_query = xtc_db_query("SELECT bitem_id FROM " . TABLE_BLOG_ITEMITEM . " WHERE language_id = " . (int) $_SESSION['languages_id'] . " AND item_id = '" . (int) $_GET['item'] . "';");
while ($caterlaubt = xtc_db_fetch_array($caterlaubt_query)) {
    $cater[$r] = $caterlaubt['bitem_id'];
    $r++;
}
while ($selbart = xtc_db_fetch_array($myitem_query)) {
    if (!isset($cater) || !in_array($selbart['id'], $cater)) {
        $selblog[$i] = array(
            'id' => $selbart['item_id'],
            'text' => $selbart['name']
        );
    }
    $i++;
}
$module_smarty->assign('MEBART', xtc_draw_pull_down_menu('blogitem', $selblog, '', ''));
$module_smarty->assign('BIPOS', xtc_draw_input_field('biposition'));

$myart_query = xtc_db_query("SELECT 
								pd.*, 
								p.products_id AS cid, 
								p.products_image, 
								p.products_status
								FROM ".TABLE_PRODUCTS." AS p 
								JOIN ".TABLE_PRODUCTS_DESCRIPTION." AS pd ON(pd.products_id = p.products_id AND pd.language_id = '" . (int) $_SESSION['languages_id'] . "')
								WHERE 
								p.products_status = '1';");
$caterlaubt_query = xtc_db_query("SELECT art_id FROM " . TABLE_BLOG_ITEMART . " WHERE language_id = " . (int) $_SESSION['languages_id'] . " AND item_id = '" . (int) $_GET['item'] . "';");
$selart[0] = array('id' => '0', 'text' => 'Alle');
$i = 1;
$r = 0;
while ($caterlaubt = xtc_db_fetch_array($caterlaubt_query)) {
    $cater[$r] = $caterlaubt['art_id'];
    $r++;
}
while ($selartdb = xtc_db_fetch_array($myart_query)) {
    if (!isset($cater) || !in_array($selart['cid'], $cater)) {
        $selart[$i] = array(
            'id' => $selartdb['cid'],
            'text' => $selartdb['products_name']
        );
    }
    $i++;
}

$module_smarty->assign('MEART', xtc_draw_pull_down_menu('artikel', $selart, '', ''));
$module_smarty->assign('APOS', xtc_draw_input_field('aposition'));

$mykats_query = xtc_db_query("SELECT 
								cd.*, 
								ca.categories_id AS cid, 
								ca.categories_image, 
								ca.categories_status 
							FROM ".TABLE_CATEGORIES." AS ca
							JOIN ".TABLE_CATEGORIES_DESCRIPTION." AS cd ON(ca.categories_id = cd.categories_id AND cd.language_id = '" . (int) $_SESSION['languages_id'] . "')
							WHERE ca.categories_status = '1' ");

$caterlaubt_query = xtc_db_query("SELECT kat_id FROM " . TABLE_BLOG_ITEMKAT . " WHERE language_id = " . (int) $_SESSION['languages_id'] . " AND item_id = " . (int) $_GET['item'] . " ");
$selkat[0] = array('id' => '0', 'text' => 'Alle');
$i = 1;
$r = 0;
while ($caterlaubt = xtc_db_fetch_array($caterlaubt_query)) {
    $cater[$r] = $caterlaubt['kat_id'];
    $r++;
}
while ($selbkat = xtc_db_fetch_array($mykats_query)) {
    if (!isset($cater) || !in_array($selbart['id'], $cater)) {
        $selkat[$i] = array(
            'id' => $selbkat['cid'],
            'text' => $selbkat['categories_name']
        );
    }
    $i++;
}
$module_smarty->assign('MEKATS', xtc_draw_pull_down_menu('kategorie', $selkat, '', 'style="width:100px; float:left;margin-right:2%"'));
$module_smarty->assign('KPOS', xtc_draw_input_field('kposition'));
$module_smarty->assign('TPOS', xtc_draw_input_field('tposition'));


$myblocks = '';
$myblocks_query1 = xtc_db_query("SELECT * FROM " . TABLE_BLOG_ITEMTEXT . " WHERE item_id = " . (int) $_GET['item'] . " AND language_id = '" . (int) $_SESSION['languages_id'] . "';");
$i = 1;
while ($mytext = xtc_db_fetch_array($myblocks_query1)) {
    $myblocks[$i]['position'] .= $mytext['position'];
    $myblocks[$i]['typ'] .= 'Textarea';
    $myblocks[$i]['tblock_id'] .= $mytext['tblock_id'];
    $myblocks[$i]['description'] .= $mytext['description'];
    $i++;
}
$myblocks_query2 = xtc_db_query("SELECT * FROM " . TABLE_BLOG_ITEMIMG . " WHERE item_id = " . (int) $_GET['item'] . " AND image_nr = '1';");

while ($mytext = xtc_db_fetch_array($myblocks_query2)) {
    $myblocks[$i]['position'] .= $mytext['position'];
    $myblocks[$i]['typ'] .= 'SlideShow';
    $myblocks[$i]['tblock_id'] .= $mytext['slid_id'];
    if ($mytext['image'] == '') {
        $mytext['image'] = 'noimage.gif';
    }
    $myblocks[$i]['description'] .= DIR_WS_CATALOG_IMAGES . 'blog_image/thumbnail_images/' . $mytext['image'];
    $i++;
}

$myblocks_query3 = xtc_db_query("SELECT * FROM " . TABLE_BLOG_ITEMKAT . " WHERE item_id = " . (int) $_GET['item'] . " AND language_id = '" . (int) $_SESSION['languages_id'] . "';");
while ($mytext = xtc_db_fetch_array($myblocks_query3)) {
    $myblocks[$i]['position'] .= $mytext['position'];
    $myblocks[$i]['typ'] .= 'Kategorie';
    $myblocks[$i]['tblock_id'] .= $mytext['kat_id'];
    $myblocks[$i]['description'] .= $mytext['name'];
    $i++;
}

$myblocks_query4 = xtc_db_query("SELECT * FROM " . TABLE_BLOG_ITEMART . " WHERE item_id = " . (int) $_GET['item'] . " AND language_id = '" . (int) $_SESSION['languages_id'] . "';");
while ($mytext = xtc_db_fetch_array($myblocks_query4)) {
    $myblocks[$i]['position'] .= $mytext['position'];
    $myblocks[$i]['typ'] .= 'Artikel';
    $myblocks[$i]['tblock_id'] .= $mytext['art_id'];
    $myblocks[$i]['description'] .= $mytext['name'];
    $i++;
}
$myblocks_query5 = xtc_db_query("SELECT * FROM " . TABLE_BLOG_ITEMITEM . " WHERE item_id = " . (int) $_GET['item'] . " AND language_id = '" . (int) $_SESSION['languages_id'] . "';");
while ($mytext = xtc_db_fetch_array($myblocks_query5)) {
    $myblocks[$i]['position'] .= $mytext['position'];
    $myblocks[$i]['typ'] .= 'Blogbeitrag';
    $myblocks[$i]['tblock_id'] .= $mytext['bitem_id'];
    $myblocks[$i]['description'] .= $mytext['name'];
    $i++;
}
if ($myblocks != '') {
    asort($myblocks);
    $module_smarty->assign('BLOECKE', $myblocks);
    $module_smarty->assign('myitem', $_GET['item']);
}
